package com.heima.wemedia.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmChannelDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/v1/channel")
@Slf4j
public class WmChannelController {
    @Autowired
    private WmChannelService wmChannelService;

    /**
     * 获取频道列表
     *
     * @return
     */
    @GetMapping("channels")
    public ResponseResult channels() {
        log.info("获取频道列表接口被请求了....");
        return wmChannelService.findAll();
    }

    /**
     * 删除频道
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    public ResponseResult deleteById(@PathVariable Integer id){
         return wmChannelService.deleteById(id);
    }

    /**
     * 根据频道名称模糊分页查询
     * @param wmChannelDto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmChannelDto wmChannelDto){
        return wmChannelService.findByPage(wmChannelDto);
    }

    /**
     * 新增频道
     * @param wmChannel
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmChannel wmChannel){
        return wmChannelService.insert(wmChannel);
    }

    /**
     * 修改(更新)频道
     * @param wmChannel
     * @return
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody WmChannel wmChannel){
        return wmChannelService.reNew(wmChannel);
    }

}
